package com.zz.arrays;

import java.util.Arrays;
import java.util.function.IntToDoubleFunction;

public class Test {
    public static void main(String args[]){
        //1.public static String toString(类型[] arr):返回数组的内容
        int[] arr = {10, 123, 34, 34};
        System.out.println(Arrays.toString(arr));

        //2.public static 类型[] copyOf(类型[] arr, int newLength):拷贝数组，可以指定数组的长度
        int arr2[] = Arrays.copyOf(arr, 3);
        System.out.println(Arrays.toString(arr2));

        //3.public static copyOf(类型[] arr, int newLength)：拷贝数组，可以指定数组的长度
        int[] arr3= Arrays.copyOf(arr, 10);
        System.out.println(Arrays.toString(arr3));

        /**
         * 4.public static serAll(double[] array, IntToDoubleFunction generator)，
         * 把数组中的原数组改为新数据存进去
         */
        double[] prices = {89, 57, 3997};
        //把所有的价格都打八折，然后存进去
        Arrays.setAll(prices, new IntToDoubleFunction() {
            @Override
            public double applyAsDouble(int value) {
                //value = 0 1 2
                return prices[value] * 0.8;
            }
        });
        System.out.println(Arrays.toString(prices));

        //5.public static void sort(类型[] arr),对数组进行排序（默认升序）
       Arrays.sort(prices);
       System.out.println(Arrays.toString(prices));
    }
}
